<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: gripperExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('gripperExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">gripperExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Example program demonstrating use of the Pioneer gripper.Shows how to control the Pioneer 2DOF gripper accessory. In addition to the arrow keys to teleoperate the robot, Use the following keyboard keys to control it: u Lift the gripper up d Lift the gripper down o Open the gripper c Close the gripper s Stop gripper movement.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classArModeGripper.html" title="Mode for controlling the gripper. ">ArModeGripper</a> (the gripper control mode used in the "demo" program)</dd></dl>
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"></div><div class="line"><span class="comment">// Adds robot callback to print gripper status.</span></div><div class="line"><span class="keyword">class </span>PrintGripStatus</div><div class="line">{</div><div class="line">  <a name="_a0"></a><a class="code" href="classArGripper.html">ArGripper</a>* myGripper;</div><div class="line">  <a name="_a1"></a><a class="code" href="classArFunctorC.html">ArFunctorC&lt;PrintGripStatus&gt;</a> myPrintCB;</div><div class="line"><span class="keyword">public</span>:</div><div class="line">  PrintGripStatus(<a class="code" href="classArGripper.html">ArGripper</a>* gripper) : </div><div class="line">    myGripper(gripper),</div><div class="line">    myPrintCB(<span class="keyword">this</span>, &amp;PrintGripStatus::printStatus)</div><div class="line">  {</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> addRobotTask(<a name="_a2"></a><a class="code" href="classArRobot.html">ArRobot</a>* robot)</div><div class="line">  {</div><div class="line">    robot-&gt;<a name="a3"></a><a class="code" href="classArRobot.html#a50070f4e19b91aaac20772d15d9ad805">addUserTask</a>(<span class="stringliteral">&quot;PrintGripStatus&quot;</span>, 10, &amp;myPrintCB);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> printStatus()</div><div class="line">  {</div><div class="line">    myGripper-&gt;<a name="a4"></a><a class="code" href="classArGripper.html#a9146d316254173bad9c81a28d3f86efa">logState</a>();</div><div class="line">  }</div><div class="line">};</div><div class="line"></div><div class="line"><span class="comment">// Adds key handler callbacks for controlling the gripper</span></div><div class="line"><span class="keyword">class </span>GripperControlHandler</div><div class="line">{</div><div class="line">  <a class="code" href="classArGripper.html">ArGripper</a>* myGripper;</div><div class="line">  <a name="_a5"></a><a class="code" href="classArFunctorC.html">ArFunctorC&lt;GripperControlHandler&gt;</a> myUpCB;</div><div class="line">  <a class="code" href="classArFunctorC.html">ArFunctorC&lt;GripperControlHandler&gt;</a> myDownCB;</div><div class="line">  <a class="code" href="classArFunctorC.html">ArFunctorC&lt;GripperControlHandler&gt;</a> myOpenCB;</div><div class="line">  <a class="code" href="classArFunctorC.html">ArFunctorC&lt;GripperControlHandler&gt;</a> myCloseCB;</div><div class="line">  <a class="code" href="classArFunctorC.html">ArFunctorC&lt;GripperControlHandler&gt;</a> myStopCB;</div><div class="line"><span class="keyword">public</span>:</div><div class="line">  GripperControlHandler(<a class="code" href="classArGripper.html">ArGripper</a>* gripper) : </div><div class="line">    myGripper(gripper),</div><div class="line">    myUpCB(<span class="keyword">this</span>, &amp;GripperControlHandler::liftUp),</div><div class="line">    myDownCB(<span class="keyword">this</span>, &amp;GripperControlHandler::liftDown),</div><div class="line">    myOpenCB(<span class="keyword">this</span>, &amp;GripperControlHandler::open),</div><div class="line">    myCloseCB(<span class="keyword">this</span>, &amp;GripperControlHandler::close),</div><div class="line">    myStopCB(<span class="keyword">this</span>, &amp;GripperControlHandler::stop)</div><div class="line">  {</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> addKeyHandlers(<a class="code" href="classArRobot.html">ArRobot</a> *robot)</div><div class="line">  {</div><div class="line">    <a name="_a6"></a><a class="code" href="classArKeyHandler.html">ArKeyHandler</a> *keyHandler = <a name="a7"></a><a class="code" href="classAria.html#a5b8042b38b19d6a5d3cfbed4df483e67">Aria::getKeyHandler</a>();</div><div class="line">    <span class="keywordflow">if</span>(keyHandler == NULL)</div><div class="line">    {</div><div class="line">      keyHandler = <span class="keyword">new</span> <a class="code" href="classArKeyHandler.html">ArKeyHandler</a>();</div><div class="line">      <a name="a8"></a><a class="code" href="classAria.html#a9e5496a4ec2c379c8e18706922b57cc1">Aria::setKeyHandler</a>(keyHandler);</div><div class="line">      robot-&gt;<a name="a9"></a><a class="code" href="classArRobot.html#ab4ea516667d2358f35b435d97b616ab1">attachKeyHandler</a>(keyHandler);</div><div class="line">    }</div><div class="line">    keyHandler-&gt;<a name="a10"></a><a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<a name="a11"></a><a class="code" href="classArKeyHandler.html#a665246cd772590dd02ea299dd047899ca0a916e5fd9baf9ed01442a1e0d996f9c">ArKeyHandler::PAGEUP</a>, &amp;myUpCB);</div><div class="line">    keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;u&#39;</span>, &amp;myUpCB);</div><div class="line">    keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<a name="a12"></a><a class="code" href="classArKeyHandler.html#a665246cd772590dd02ea299dd047899caabbedf3b93d1e2a1f09298be2dbeca30">ArKeyHandler::PAGEDOWN</a>, &amp;myDownCB);</div><div class="line">    keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;d&#39;</span>, &amp;myDownCB);</div><div class="line">    keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;o&#39;</span>, &amp;myOpenCB);</div><div class="line">    keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;c&#39;</span>, &amp;myCloseCB);</div><div class="line">    keyHandler-&gt;<a class="code" href="classArKeyHandler.html#ad5442ebb21cd242ab168e94686e06759">addKeyHandler</a>(<span class="charliteral">&#39;s&#39;</span>, &amp;myStopCB);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> liftUp()</div><div class="line">  {</div><div class="line">    <a name="a13"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a14"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;Moving gripper lift up...&quot;</span>);</div><div class="line">    myGripper-&gt;<a name="a15"></a><a class="code" href="classArGripper.html#adf6831c4e2a8105459e60e5e4bf4d4be">liftUp</a>();</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> liftDown()</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;Moving gripper lift down...&quot;</span>);</div><div class="line">    myGripper-&gt;<a name="a16"></a><a class="code" href="classArGripper.html#ab858d73d857c1d7367c5e8bee237ee82">liftDown</a>();</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> stop()</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;Stopping gripper...&quot;</span>);</div><div class="line">    myGripper-&gt;<a name="a17"></a><a class="code" href="classArGripper.html#a44482f3fa21825f4616f9779c1692449">gripperHalt</a>(); <span class="comment">// stops both lift an grip</span></div><div class="line">    <span class="comment">//myGripper-&gt;liftStop(); // stops just the lift</span></div><div class="line">    <span class="comment">//myGripper-&gt;gripStop(); // stops just the gripper</span></div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> close()</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;Closing gripper...&quot;</span>);</div><div class="line">    myGripper-&gt;<a name="a18"></a><a class="code" href="classArGripper.html#a014f7e6e13625a748cfbded1c3c9a7fe">gripClose</a>();</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> open()</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;Opening gripper...&quot;</span>);</div><div class="line">    myGripper-&gt;<a name="a19"></a><a class="code" href="classArGripper.html#a23c923a8c98cb11bc3575079f8bf76ea">gripOpen</a>();</div><div class="line">  }</div><div class="line"></div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv) </div><div class="line">{</div><div class="line">  <a name="a20"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <a name="_a21"></a><a class="code" href="classArArgumentParser.html">ArArgumentParser</a> parser(&amp;argc, argv);</div><div class="line">  parser.<a name="a22"></a><a class="code" href="classArArgumentParser.html#a501694b62a7f8b0c3cadd84aeafe1b35">loadDefaultArguments</a>();</div><div class="line">  <a class="code" href="classArRobot.html">ArRobot</a> robot;</div><div class="line">  <a class="code" href="classArGripper.html">ArGripper</a> gripper(&amp;robot);</div><div class="line"></div><div class="line">  <span class="comment">// Connect to the robot, get some initial data from it such as type and name,</span></div><div class="line">  <span class="comment">// and then load parameter files for this robot.</span></div><div class="line">  <a name="_a23"></a><a class="code" href="classArRobotConnector.html">ArRobotConnector</a> robotConnector(&amp;parser, &amp;robot);</div><div class="line">  <span class="keywordflow">if</span>(!robotConnector.<a name="a24"></a><a class="code" href="classArRobotConnector.html#ab192ac393d9cc1e5b61b1a82b08d085d">connectRobot</a>())</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a25"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;gripperExample: Could not connect to the robot.&quot;</span>);</div><div class="line">    <span class="keywordflow">if</span>(parser.<a name="a26"></a><a class="code" href="classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">    {</div><div class="line">        <span class="comment">// -help not given</span></div><div class="line">        <a name="a27"></a><a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">        <a name="a28"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (!<a name="a29"></a><a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1">Aria::parseArgs</a>() || !parser.<a class="code" href="classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">  {</div><div class="line">    <a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">  }</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;gripperExample: Connected to robot.&quot;</span>);</div><div class="line"></div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;gripperExample: GripperType=%d&quot;</span>, gripper.<a name="a30"></a><a class="code" href="classArGripper.html#a8e162a9ba0ad2351c63bf5b4d35dba8c">getType</a>());</div><div class="line">  gripper.<a class="code" href="classArGripper.html#a9146d316254173bad9c81a28d3f86efa">logState</a>();</div><div class="line">  <span class="keywordflow">if</span>(gripper.<a class="code" href="classArGripper.html#a8e162a9ba0ad2351c63bf5b4d35dba8c">getType</a>() == <a name="a31"></a><a class="code" href="classArGripper.html#a565fcee58e47e92596e472c34f359368ae1f5be72993ec3d941480086a6948e57">ArGripper::NOGRIPPER</a>)</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;gripperExample: Error: Robot does not have a gripper. Exiting.&quot;</span>);</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(-1);</div><div class="line">    <span class="keywordflow">return</span> -1;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// Teleoperation actions with obstacle-collision avoidance</span></div><div class="line">  <a name="_a32"></a><a class="code" href="classArActionLimiterTableSensor.html">ArActionLimiterTableSensor</a> tableLimit;</div><div class="line">  robot.<a name="a33"></a><a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;tableLimit, 110);</div><div class="line">  <a name="_a34"></a><a class="code" href="classArActionLimiterForwards.html">ArActionLimiterForwards</a> limitNearAction(<span class="stringliteral">&quot;near&quot;</span>, 300, 600, 250);</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;limitNearAction, 100);</div><div class="line">  <a class="code" href="classArActionLimiterForwards.html">ArActionLimiterForwards</a> limitFarAction(<span class="stringliteral">&quot;far&quot;</span>, 300, 1100, 400);</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;limitFarAction, 90);</div><div class="line">  <a name="_a35"></a><a class="code" href="classArActionLimiterBackwards.html">ArActionLimiterBackwards</a> limitBackAction;</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;limitBackAction, 50);</div><div class="line">  <a name="_a36"></a><a class="code" href="classArActionJoydrive.html">ArActionJoydrive</a> joydriveAction(<span class="stringliteral">&quot;joydrive&quot;</span>, 400, 15);</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;joydriveAction, 40);</div><div class="line">  joydriveAction.<a name="a37"></a><a class="code" href="classArActionJoydrive.html#a2d2e8053a6a49487c5dbeadcbcc44556">setStopIfNoButtonPressed</a>(<span class="keyword">false</span>);</div><div class="line">  <a name="_a38"></a><a class="code" href="classArActionKeydrive.html">ArActionKeydrive</a> keydriveAction;</div><div class="line">  robot.<a class="code" href="group__easy.html#ga9ab030786d423237d3e4aa06c0e9d8ce">addAction</a>(&amp;keydriveAction, 30);</div><div class="line">  </div><div class="line"></div><div class="line">  <span class="comment">// Handlers to control the gripper and print out info (classes defined above)</span></div><div class="line">  PrintGripStatus printStatus(&amp;gripper);</div><div class="line">  GripperControlHandler gripControl(&amp;gripper);</div><div class="line">  printStatus.addRobotTask(&amp;robot);</div><div class="line">  gripControl.addKeyHandlers(&amp;robot);</div><div class="line"></div><div class="line">  <span class="comment">// enable motors and run (if we lose connection to the robot, exit)</span></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;You may now operate the robot with arrow keys or joystick. Operate the gripper with the u, d, o, c, and page up/page down keys.&quot;</span>);</div><div class="line">  robot.<a name="a39"></a><a class="code" href="group__easy.html#gaa3657bebab0086dd14ed0c8c3f76dc8b">enableMotors</a>();</div><div class="line">  robot.<a name="a40"></a><a class="code" href="classArRobot.html#a3c1c3056633caf455c8265259f57f6d7">run</a>(<span class="keyword">true</span>);</div><div class="line">  </div><div class="line">  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"></div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
